package com.airbnb.mvrx.sample.features.book.views

import android.content.Context
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.TextView
import com.airbnb.epoxy.ModelProp
import com.airbnb.epoxy.ModelView
import com.airbnb.mvrx.sample.Utils
import com.example.mvrxstudy.R
import com.facebook.drawee.view.SimpleDraweeView

@ModelView(autoLayout = ModelView.Size.WRAP_WIDTH_WRAP_HEIGHT)
class BDRecommendBookItem @JvmOverloads constructor(context: Context) : FrameLayout(context) {
    private val mImage: SimpleDraweeView
    private val mTitle: TextView by lazy { findViewById<TextView>(R.id.tv_title) }

    override fun setLayoutParams(params: ViewGroup.LayoutParams?) {
        params!!.width = Utils.getDM(context).widthPixels / 3
        super.setLayoutParams(params)
    }

    init {
        inflate(context, R.layout.item_grid_book_recommend, this)
        mImage = findViewById(R.id.iv_image)
    }


    @ModelProp
    fun setImage(image: String) {
        mImage.setImageURI(image)
    }

    @ModelProp
    fun setTitle(title: String) {
        mTitle.text = title
    }

}